package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.TimerAdapter;
import flc.ast.bean.MyTimerBean;
import flc.ast.databinding.ActivityRecentAddBinding;
import flc.ast.fragment.timer.TimeFragment;
import flc.ast.utils.AppSpUtils;

public class RecentAddActivity extends BaseAc<ActivityRecentAddBinding> {

    private TimerAdapter timerAdapter;
    private List<MyTimerBean> listShow = new ArrayList<>();


    @Override
    protected int onCreate() {
        return R.layout.activity_recent_add;
    }

    @Override
    protected void initView() {
        mDataBinding.ivRecentAddBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvRecentList.setLayoutManager(new LinearLayoutManager(mContext));
        timerAdapter = new TimerAdapter();
        mDataBinding.rvRecentList.setAdapter(timerAdapter);
        timerAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        TimeFragment.selPosition = position;
        finish();
    }

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        listShow.clear();
        List<MyTimerBean> listSp = AppSpUtils.getTimerList();
        if (listSp != null && listSp.size() > 0) {
            listShow.addAll(listSp);
            timerAdapter.setList(listShow);
            mDataBinding.rvRecentList.setVisibility(View.VISIBLE);
            mDataBinding.tvRecentNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvRecentList.setVisibility(View.GONE);
            mDataBinding.tvRecentNoData.setVisibility(View.VISIBLE);
        }
    }

}